package com.djinfo.work.dao.impl;

import com.djinfo.work.common.dao.impl.BaseDaoImpl;
import com.djinfo.work.dao.QsTitleDao;
import com.djinfo.work.entity.QsTitleEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *
 * @date 2017-06-08 10:48:15
 */
@Repository("QsTitleDao")
public class QsTitleDaolmpl extends BaseDaoImpl implements QsTitleDao {

    @Override
    public void save(QsTitleEntity object) {
        if (object.getId() == null) {
            super.save(object);
        } else {
            super.update(object);
        }
    }

    @Override
    public void update(QsTitleEntity object) {
        super.update(object);
    }

    @Override
    public QsTitleEntity selectOne(String id) {
        return (QsTitleEntity)super.get(QsTitleEntity.class,id);
    }


    @Override
    public List<QsTitleEntity> page(QsTitleEntity object, Integer pageNum, Integer pageSize) {
        String hql="from QsTitleEntity where 1=1";
        if(object.getTitleName()==null||"".equals(object.getTitleName())){
            hql="from QsTitleEntity where 1=1";
        }else {
            hql="from QsTitleEntity where 1=1 and titleName like'%" + object.getTitleName() + "%' ";
        }
        return (List<QsTitleEntity>)super.pageQuery( hql,  pageNum,  pageSize);
    }

    @Override
    public Integer getAllRowCount(QsTitleEntity object) {
        String hql="";
        if("".equals(object.getTitleName())||object.getTitleName()==null){
            hql="select count(*) from QsTitleEntity";
        }else {
            hql="select count(*) from QsTitleEntity where 1=1 and titleName like'%" + object.getTitleName() + "%' ";
        }
        return super.getUniqueObject(hql).hashCode();
    }

    @Override
    public void delete(QsTitleEntity object) {
        QsTitleEntity qsTitleEntity = (QsTitleEntity)super.getByPrimaryKey(QsTitleEntity.class,object.getId());
        super.delete(qsTitleEntity);
    }

    @Override
    public List<QsTitleEntity> getTileListBySearch(QsTitleEntity qsTitleEntity) {
        String hql="from QsTitleEntity where 1=1";
        if(!"".equals(qsTitleEntity.getTitleName())&&qsTitleEntity.getTitleName()!=null){
            hql+= " and titleName like '%" + qsTitleEntity.getTitleName() + "%' ";
        }
        if(!"".equals(qsTitleEntity.getLevel())&&qsTitleEntity.getLevel()!=null){
            hql+= " and level="+qsTitleEntity.getLevel()+"";
        }

        return (List<QsTitleEntity>)super.getList(hql);
    }


    @Override
    public List getTitleListById(String hql,String id) {
        return super.getList(hql,id);
    }
    public Integer getTLevelMaxByQsId(String hql,String id){
        return super.getUniqueObject(hql,id).hashCode();
    }

    @Override
    public List getTitleListByQsIdAndLevel(String hql, String id, String level) {
        return super.getList(hql,id,level);
    }
}
